package design.graduation.novelsystem.controller;

import design.graduation.novelsystem.model.dto.ResultObj;
import design.graduation.novelsystem.model.vo.AdminLoginLogVo;
import design.graduation.novelsystem.service.AdminLoginLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author: 洪少尉
 * @Date: 2020/4/15 02:52
 * @Description: 管理员登录日志管理
 */
@RestController
@RequestMapping("adminLoginLog")
public class AdminLoginLogController {
	@Autowired
	private AdminLoginLogService adminLoginLogService;
	/**
	 * 全查询+条件查询
	 */
	@RequiresPermissions("log:show")
	@GetMapping("loadAllAdminLoginLog")
	public Object loadAllAdminLoginLog(AdminLoginLogVo adminLoginLogVo){
		return this.adminLoginLogService.queryAllAdminLoginLog(adminLoginLogVo);
	}
	/**
	 * 删除
	 */
	@RequiresPermissions("log:delete")
	@PostMapping("deleteAdminLoginLog")
	public ResultObj deleteAdminLoginLog(Integer id){
		if(this.adminLoginLogService.removeById(id)){
			return ResultObj.DELETE_SUCCESS;
		}
		return ResultObj.DELETE_ERROR;
	}

	/**
	 * 批量删除
	 */
	@RequiresPermissions("log:delete")
	@PostMapping("batchDeleteAdminLoginLog")
	public ResultObj batchDeleteAdminLoginLog(Integer[] ids){
		if(null!=ids&&ids.length>0){
			List<Integer> idsList = new ArrayList<>(Arrays.asList(ids));
			if(this.adminLoginLogService.removeByIds(idsList)){
				return ResultObj.DELETE_SUCCESS;
			}
			return ResultObj.DELETE_ERROR;
		}else{
			return ResultObj.DELETE_IDS_NULL;
		}
	}
}
